package com.qixin.total.controller;

import com.alibaba.fastjson.JSONObject;
import com.qixin.api.bean.*;
import com.qixin.api.service.ComPeopleService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.FileInputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 李许多
 * 个人认证
 * Created by aa on 2018/10/30.
 */

@Controller
@RequestMapping("/comPeople")
public class ComPeopleController {
    private static final Logger logger = LoggerFactory.getLogger(ComPeopleController.class);
    @Autowired
    ComPeopleService comPeopleService;

    /**
     * 跳转页面
     * @return
     */
    @RequestMapping("/main.html")
    public String carftl(){
        return "renzheng/personal";

    }

    @RequestMapping("/select")
    @ResponseBody
    public ResultPage<ComPeople> list(VoPage voPage) {
        ResultPage<ComPeople> resultPage=comPeopleService.selectALL(voPage);
        return  resultPage;
    }
    @RequestMapping("/selectphone")
    @ResponseBody
    public ResultPage<ComPeople> selectphone(VoPage voPage, Long phone) {
        Map map=new HashMap();
        map.put("phone",phone);
        ResultPage<ComPeople> resultPage=comPeopleService.selectphone(voPage,phone);
        return  resultPage;
    }
    @RequestMapping("/check.html")
    public String check(String peoepleUrla, String peoepleUrlb, Long id, Model model){
        String phonea=comPeopleService.phonea(id);
        String phoneb=comPeopleService.phoneb(id);
        model.addAttribute("phonea",phonea);
        model.addAttribute("phoneb",phoneb);
        model.addAttribute("peoepleUrla",peoepleUrla);
        model.addAttribute("peoepleUrlb", peoepleUrlb);
        return "/renzheng/checkpeople";

    }
    @RequestMapping("/getPhoto")
    public   void getPhoto(HttpServletResponse response,@RequestParam("path") String path) throws Exception {
        File file = new File(path);
        FileInputStream fis; fis = new FileInputStream(file);
        long size = file.length();
        byte[] temp = new byte[(int) size];
        fis.read(temp, 0, (int) size);
        fis.close();
        byte[] data = temp;
        response.setContentType("image/png");
        OutputStream out = response.getOutputStream();
        out.write(data);
        out.flush();
        out.close();
    }

    /**
     * 修改
     * @param param
     * @return
     */
    @RequestMapping("/updatecheck")
    @ResponseBody
    public  boolean updatecheck(String param){
        ComPeople comPeople  = JSONObject.parseObject(param,ComPeople .class);
        if(comPeopleService.updateById(comPeople)){
            return  true;
        }else{
            return false;
        }
    }

}

